//
//  LLtalkVc.m
//  CustomerService_Lee
//
//  Created by MrLee on 2017/6/9.
//  Copyright © 2017年 MrLee.com. All rights reserved.
//

#define SWIDTH [UIScreen mainScreen].bounds.size.width
#define SHIGHT [UIScreen mainScreen].bounds.size.height

#import "LLtalkVc.h"
#import "GKCover.h"
#import "PopView.h"

@interface LLtalkVc ()
{

    PopView *_popView; //弹出评价视图
    
    CGFloat keyboardHeight;
}

@end

@implementation LLtalkVc

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self addNoticeForKeyboard];
    
    [self initUI];
}

#pragma mark ------- 设置UI
-(void)initUI
{

    self.title = @"客服";
    self.view.backgroundColor = [UIColor whiteColor];
    UIButton *rightBtn = [[UIButton alloc]initWithFrame:CGRectMake(0,0,30,30)];
    rightBtn.adjustsImageWhenDisabled = NO;
    [rightBtn setImage:[UIImage imageNamed:@"icon_chat"] forState:UIControlStateNormal];
    
    [rightBtn addTarget:self action:@selector(comment:) forControlEvents:UIControlEventTouchUpInside];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    
}

#pragma mark ------- 点击评价客服按钮
-(void)comment:(UIButton *)btn
{

    _popView = [PopView allocPop];
    
    _popView.submitBlock = ^(NSString *name) {
        
        NSLog(@"是否匿名----%@",name);
        [MXUtility showTips:@"向后台提交评价..."];
    };

    _popView.gk_size = CGSizeMake(SWIDTH-60,SWIDTH-60);
    [GKCover translucentWindowCenterCoverContent:_popView animated:YES];
    
}

#pragma mark ------- 键盘通知
- (void)addNoticeForKeyboard {
    
    //注册键盘出现的通知
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification object:nil];
    //注册键盘消失的通知
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillHide:)
                                                 name:UIKeyboardWillHideNotification object:nil];
}

#pragma mark ------- 键盘显示
- (void) keyboardWillShow:(NSNotification *)notification {
    NSDictionary *info = [notification userInfo];
    
    CGFloat animationDuration = [[info valueForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
    
    CGRect keyboardBounds = [info[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    keyboardHeight = keyboardBounds.size.height;

    [GKCover rise:animationDuration];
    
    [_popView.textV becomeFirstResponder];
    

}

#pragma mark ------- 键盘隐藏

-(void)keyboardWillHide:(NSNotification *)notification
{


    NSDictionary *info = [notification userInfo];

    CGFloat animationDuration = [[info valueForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
    
    CGRect keyboardBounds = [info[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    keyboardHeight = keyboardBounds.size.height;
    
    [GKCover reset:animationDuration];
    
}

@end
